package com.itheima.health.mobile.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.mobile.utils.SMSUtils;
import com.itheima.health.mobile.utils.ValidateCodeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：zboy
 * @date ：
 * @description ：
 * @version: 1.0
 */
@RequestMapping("/mobile/validateCode")
@RestController
public class ValidateCodeController {

    @RequestMapping("/send4Order")
    public Result send4Order(String telephone){
        // 生成短信验证码
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        try{
            // 调用三方发送短信
           // SMSUtils.sendShortMessage(telephone,code.toString());
        }catch(Exception e){
            e.printStackTrace();
            return new Result(false, MessageConst.SEND_VALIDATECODE_FAIL);
        }
        System.err.println("发送的手机验证码为："+code);
        // 把验证码缓存到redis
        return new Result(true,MessageConst.SEND_VALIDATECODE_SUCCESS);
    }


}
